package com.example.hmsrxjava_demo;

import com.example.hmsrxjava_demo.base.BaseMvpAbility;
import com.example.hmsrxjava_demo.bean.BaseObjectBean;
import com.example.hmsrxjava_demo.bean.LoginBean;
import com.example.hmsrxjava_demo.contract.MainContract;
import com.example.hmsrxjava_demo.presenter.MainPresenter;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.agp.window.dialog.ToastDialog;





public class MainAbility extends BaseMvpAbility<MainPresenter>implements MainContract.View {
    private TextField textUsername, textpasswrod;
    private String username, password;
    private Button loginBtn;
    private MainPresenter presenter;


    @Override
    public int getLayoutId() {
        return ResourceTable.Layout_ability_main;
    }


    @Override
    public void initView() {
        textUsername= (TextField) findComponentById(ResourceTable.Id_text_username);
        textpasswrod= (TextField) findComponentById(ResourceTable.Id_text_password);
        presenter=new MainPresenter();
        presenter.attachView(this);
        loginBtn= (Button) findComponentById(ResourceTable.Id_login_btn);
        if(loginBtn!=null){
            loginBtn.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    System.out.println("点击登录按钮");
                    username=textUsername.getText();
                    password=textpasswrod.getText();
                    if(username!=null&&password!=null){
                        presenter.login(username,password);
                        // login(username,password);
                    }else {
                        new ToastDialog(MainAbility.this).setText("账号密码不输不能为空").show();                    }
                }
            });
        }
    }

    @Override
    public void onSuccess(BaseObjectBean<LoginBean> bean) {
        System.out.println(bean.getErrorCode()+bean.getErrorMsg());
        new ToastDialog(MainAbility.this).setText(bean.getErrorCode()+bean.getErrorMsg()).show();

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(String errMessage) {

    }



}




